package cn.uce.cc.srv.utils;

import cn.uce.base.vo.AbnormalDealVo;
import cn.uce.base.vo.AbnormalVo;
import cn.uce.base.vo.ProblemInfoVo;
import cn.uce.base.vo.ProblemReportInfVo;
import cn.uce.utils.StringUtil;
import com.alibaba.fastjson.JSONObject;

import java.util.*;

/**
 * 问题件转化
 * @author Administrator
 *
 */
public class ScreenBusiAbnPubApiConver {


	public static List converterPro(String pro_api1, String pro_api2) {
        List pro_lst = null;
        List pro_lst2 = null;
		if(!ScreenBusiConditionUtils.isEmptyForApi(pro_api1, "data") && !ScreenBusiConditionUtils.isEmptyForApi(pro_api2, "data")) {
			return pro_lst;
		}
		ProblemInfoVo problemInfo = null;
		if(ScreenBusiConditionUtils.isEmptyForApi(pro_api1, "data")) {
			//问题件v1.0接口
			JSONObject jSONObject = JSONObject.parseObject(pro_api1);
			String pro_temp =  jSONObject.getString("data");
			pro_lst = jSONObject.parseArray(pro_temp);
		}
		if(ScreenBusiConditionUtils.isEmptyForApi(pro_api2, "data")) {
			//问题件v2.0接口
			JSONObject jSONObject2 = JSONObject.parseObject(pro_api2);
			String pro_temp2 =  jSONObject2.getString("data");
			pro_lst2 = jSONObject2.parseArray(pro_temp2);
		}

		if(null != pro_lst && null != pro_lst2) {
			pro_lst.addAll(pro_lst2);
		}else if(null == pro_lst && null != pro_lst2) {
			pro_lst = pro_lst2;
		}

		List<ProblemInfoVo> lst_pro = new ArrayList<ProblemInfoVo>();
		for (Object obj : pro_lst) {
			problemInfo = new ProblemInfoVo();
			String pro_obj = obj.toString();
			AbnormalVo abnormalVo = JSONObject.parseObject(pro_obj,AbnormalVo.class);
			if(StringUtil.isNotBlank(abnormalVo.getAbnormalCode())) {
				problemInfo.setProblemNum(abnormalVo.getAbnormalCode());
			}
			//问题件状态	
			
			if(StringUtil.isNotBlank(abnormalVo.getDealEmpName())) {
				problemInfo.setReplyer(abnormalVo.getDealEmpName());	
			}
			if(StringUtil.isNotBlank(abnormalVo.getAbnormalStatus())) {
				problemInfo.setProblemStatus(abnormalVo.getAbnormalStatus());	
			}
			if(StringUtil.isNotBlank(abnormalVo.getDealContent())) {
				problemInfo.setReplyContent(abnormalVo.getDealContent());
			}
			if(StringUtil.isNotBlank(abnormalVo.getAbnormalCategoryName())) {
				problemInfo.setProblemType(abnormalVo.getAbnormalCategoryName());
			}
			
			if(StringUtil.isNotBlank(abnormalVo.getAbnormalDetail())) {
				problemInfo.setProblemDetil(abnormalVo.getAbnormalDetail());
			}
			//wenti类型
			if(StringUtil.isNotBlank(abnormalVo.getAbnormalTypeName())) {
				problemInfo.setProblemStyle(abnormalVo.getAbnormalTypeName());
			}
			//上报省
			if(StringUtil.isNotBlank(abnormalVo.getReportProvinceName())) {
				problemInfo.setReportPro(abnormalVo.getReportProvinceName());
			}
			//上报部门
			if(StringUtil.isNotBlank(abnormalVo.getReportDepartName())) {
				problemInfo.setReportDep(abnormalVo.getReportDepartName());
			}
			//上报人
			if(StringUtil.isNotBlank(abnormalVo.getReportEmpName())) {
				problemInfo.setReporter(abnormalVo.getReportEmpName());
			}
			//上报时间
			if(null != abnormalVo.getCreaterTime()) {
				problemInfo.setReportTime(DateUtil.dateToString(abnormalVo.getCreaterTime(), "yyyy-MM-dd HH:mm"));
			}
			//业务类型
			if(StringUtil.isNotBlank(abnormalVo.getBusinessTypeName())) {
				problemInfo.setBusinessType(abnormalVo.getBusinessTypeName());
			}
			lst_pro.add(problemInfo);
		}
		return lst_pro;
	}
	
	public static Map converterProDetil(String pro_detil1, String pro_detil2) {
		Map<String, Object> map =new HashMap();
		if(!ScreenBusiConditionUtils.isEmptyForApi(pro_detil1, "data") && !ScreenBusiConditionUtils.isEmptyForApi(pro_detil2, "data")) {
			return map;
		}
		String str_temp = "";
		//问题件v1.0详情
		if(ScreenBusiConditionUtils.isEmptyForApi(pro_detil1, "data")) {
			JSONObject jSONObject = JSONObject.parseObject(pro_detil1);
			str_temp = jSONObject.getString("data");
		}
		//问题件v2.0详情
		if(ScreenBusiConditionUtils.isEmptyForApi(pro_detil2, "data")) {
			JSONObject jSONObject2 = JSONObject.parseObject(pro_detil2);
			str_temp = jSONObject2.getString("data");
		}

		AbnormalVo AbnormalVo = JSONObject.parseObject(str_temp,AbnormalVo.class);
		ProblemReportInfVo problemReportInfo = new ProblemReportInfVo();
		if(StringUtil.isNotBlank( String.valueOf(AbnormalVo.getWaybillNo()) )) {
			problemReportInfo.setWayBillNumber(String.valueOf(AbnormalVo.getWaybillNo()));
		}
		if(StringUtil.isNotBlank( AbnormalVo.getCarNo())) {
			problemReportInfo.setNumberPlate(AbnormalVo.getCarNo());
		}
		if(StringUtil.isNotBlank( AbnormalVo.getStowageNo())) {
			problemReportInfo.setLoadingOrderNumber(AbnormalVo.getStowageNo());
		}
		if(StringUtil.isNotBlank(AbnormalVo.getStatusName())) {
				problemReportInfo.setNeedToReply(AbnormalVo.getStatusName());
		}
		if(StringUtil.isNotBlank( AbnormalVo.getReceiveCompName())) {
			problemReportInfo.setReceivingCompany(AbnormalVo.getReceiveCompName());
		}
		if(StringUtil.isNotBlank( AbnormalVo.getReportDepartName())) {
			problemReportInfo.setReportingDepartment(AbnormalVo.getReportDepartName());
		}
		if(StringUtil.isNotBlank( AbnormalVo.getReportCompName())) {
			problemReportInfo.setReportingToTheCompany(AbnormalVo.getReportCompName());
		}
		if(StringUtil.isNotBlank( AbnormalVo.getAbnormalTypeName())) {
			problemReportInfo.setQuestionType(AbnormalVo.getAbnormalTypeName());
		}
		//问题类别
		if(StringUtil.isNotBlank( AbnormalVo.getAbnormalCategoryName())) {
			problemReportInfo.setProblemCategory(AbnormalVo.getAbnormalCategoryName());
		}
		if(StringUtil.isNotBlank( AbnormalVo.getReceiveDepartName())) {
			problemReportInfo.setReceivingDepartment(AbnormalVo.getReceiveDepartName());
		}
		if(StringUtil.isNotBlank( AbnormalVo.getPackType())) {
			problemReportInfo.setPacking(AbnormalVo.getPackType());
		}
		if(StringUtil.isNotBlank( String.valueOf(AbnormalVo.getBusinessType()))) {
			problemReportInfo.setBusinessType(String.valueOf(AbnormalVo.getBusinessType()));
			  if (AbnormalVo.getBusinessType() == null) {
				  problemReportInfo.setBusinessType("全部");
	            } else if (AbnormalVo.getBusinessType() == 1) {
	            	problemReportInfo.setBusinessType("企业内");
	            } else if (AbnormalVo.getBusinessType() == 2) {
	            	problemReportInfo.setBusinessType("企业外");
	            }
		}
		if(null != AbnormalVo.getErrorNum()) {
			problemReportInfo.setNumberOfAbnormalParts(String.valueOf(AbnormalVo.getErrorNum()));
		}
		
		//子单详情
//		if(StringUtil.isNotBlank( String.valueOf(AbnormalVo.getErrorNum()))) {
//			problemReportInfoVo.setNumberOfAbnormalParts(String.valueOf(AbnormalVo.getErrorNum()));
//		}
		if(StringUtil.isNotBlank( String.valueOf(AbnormalVo.getAbnormalDetail()))) {
			problemReportInfo.setProblemDetails(String.valueOf(AbnormalVo.getAbnormalDetail()));
		}
		
		if(StringUtil.isNotBlank( String.valueOf(AbnormalVo.getFileIds()))) {
			problemReportInfo.setAttachmentInformation(String.valueOf(AbnormalVo.getFileIds()));
		}
		
		List<AbnormalDealVo> lst_delabn = AbnormalVo.getAbnormalDealVo();
		if (null!=lst_delabn) {
				problemReportInfo.setReplyMessage(lst_delabn);
		}
		map.put("problemreportinfo", problemReportInfo);
		return map;
		
	}
}
